package org.scratchcrew.domain.dao;

import java.util.HashMap;
import java.util.Map;

import org.scratchcrew.domain.User;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.stereotype.Repository;

@Repository(value = "userDao")
public class UserDaoImpl extends EntityDaoSupport<User> implements UserDao {
	public UserDaoImpl() {
		super(User.class);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public User findByName(String userName){
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("userName", userName);
		User result = (User) DataAccessUtils
				.uniqueResult(getJpaTemplate().findByNamedParams(
						"select u from User u where u.userName = :userName",
						parameters));
		return result;
	}
}
